package com.lxw.nonghe.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxw.nonghe.entity.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 权限表 Mapper 接口
 * </p>
 *
 * @author lxw
 * @since 2025-04-17
 */
@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {
    IPage<Permission> selectPermissionPage(Page<Permission> page, @Param("permissionName") String permissionName);

    // 添加新方法
    @Select("SELECT p.permission_name FROM t_permission p " +
            "JOIN t_role_permission rp ON p.permission_id = rp.permission_id " +
            "JOIN t_user u ON rp.role_id = u.role_id " +
            "WHERE u.user_id = #{userId}")
    List<String> selectPermissionsByUserId(@Param("userId") Integer userId);
}
